/**
 * 
 */
package com.ginger.rabbitmq.stream;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @Description: RabbitMQ发送
 * @author 姜锋
 * @date 2019年4月2日 下午10:05:36 
 * @version V1.0   
 *
 */
@EnableBinding(Barista.class)
@Service
public class RabbitmqSender {
	
	private final static Logger logger = LoggerFactory.getLogger(RabbitmqSender.class);
	
	@Autowired
	private Barista barista;
	
	@SuppressWarnings("rawtypes")
	public String sendMessage(Object content, Map<String, Object> properties) throws Exception{
		
		
		try {
			
			MessageHeaders messageHeaders = new MessageHeaders(properties);
			Message message = MessageBuilder.createMessage(content, messageHeaders);
			boolean sendStatus = barista.logoutput().send(message);
			logger.info("---- Sending ----");
			logger.info("---- 发送数据: "+content+", sendStatus: "+sendStatus);
		} catch (Exception e) {
			logger.info("---- error ----");
		}
		
		return null;
	}
}
